-
Notifications
You must be signed in to change notification settings - Fork 3.3k
{Core} Honor expiresOn, instead of expiresIn #15901
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Core |
|
Has Bin's PR fixed it? |
Those PRs still leave some unreachable code which should be removed: return AccessToken(token, int(full_token['expiresIn'] + time.time()))
They are from ADAL cache, we prefer not to do special handling to it.
After we migrate to MSAL. |
| def _timestamp(dt): | ||
| # datetime.datetime can't be patched: | ||
| # TypeError: can't set attributes of built-in/extension type 'datetime.datetime' | ||
| # So we wrap datetime.datetime.timestamp with this function. | ||
| # https://docs.python.org/3/library/unittest.mock-examples.html#partial-mocking | ||
| # https://williambert.online/2011/07/how-to-unit-testing-in-django-with-mocking-and-patching/ | ||
| return dt.timestamp() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function serves the same purpose as azure.cli.command_modules.profile.custom._fromtimestamp introduced by #15131.
# Conflicts: # src/azure-cli-core/azure/cli/core/adal_authentication.py
| import unittest.mock as mock | ||
| from unittest.mock import MagicMock |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be improved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Delete 2nd line or delete 1st line and import all used class in mock
bim-msft
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
| return AccessToken(token, int(full_token['expires_on'])) | ||
|
|
||
| from azure.cli.core.azclierror import CLIInternalError | ||
| raise CLIInternalError("No expiresOn or expires_on is available in the token entry.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there is no expected property in the token entry, should it be AAD or ADAL issue?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I tested, it is never possible for expiresOn or expires_on to be missing.
|
/azp run |
|
Azure Pipelines successfully started running 2 pipeline(s). |
|
@jiasli , please fix CI failure |
|
/azp run |
|
Azure Pipelines successfully started running 2 pipeline(s). |
Description
#12952 uses
expiresInto calculate the expiration date:https://github.com/Azure/azure-cli/pull/12952/files#diff-7f489fcc6ae732563b52a550ccc3c32411ec118393eafd449ee9f5ab211ebf48R64
As tokens are cached,
expiresInsaved in~/.azure/accessTokens.jsonwill always be a fixed value, a little bit smaller or equal to3600. Usingfull_token['expiresIn'] + time.time()will result in an expiration time already past the actual expiration time (expiresOn).This way of computing expiration date is no different than "carving a mark on the boat to seek the sunk sword" (刻舟求剑).
Changes
expiresOn, instead ofexpiresIn.expiresInkey error in cloud shell login credentials for track 2 SDK related commands #14187) - User and service principal token entries haveexpiresOnin local time, while Managed Identity token entries hasexpires_onin epoch time.Testing Guide
Test on a local machine:
Test on a VM with Managed Identity:
To test in Cloud Shell, see #13567.